Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Getting [object Object] error in Javascript and can't identify the problem

I have a function below that when used on a webpage is causing the [object Object] error to occur and I was hoping someone could identify the issue for me. I am using this code to get the count of a items in particular SharePoint views so that I can display them in a dashboard for the users. Any suggestions appreciated.

function countViewItems(listTitle, viewName, elementClass) {
// Counts the number of items of in the view 'viewName' of the list 'listTitle'.

//get view query of the list view
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/views/getbytitle('"+viewName+"')/ViewQuery",
    type: "GET",
    headers: { 
        "ACCEPT": "application/json;odata=verbose",
    },
    success: function (data) {
        var  viewQuery=data.d.ViewQuery;
        //get item count of view
        var viewXml = '<View><Query>' + viewQuery + '</Query></View>';
        var queryPayload = {  
            'query' : {
                '__metadata': { 'type': 'SP.CamlQuery' }, 
                'ViewXml' : viewXml  
            }
        };
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems",
            type: "POST",
            data: JSON.stringify(queryPayload),
            headers: {
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "Content-Type": "application/json; odata=verbose"
            },
            success: function (data) {
                var itemCount=data.d.results.length;
                $(elementClass).html(itemCount);
            },
            error: function (data) {                     
                alert(JSON.stringify(data));
            }
        });
    },
    error: function (err) {
        alert(err);
    }
});

}

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda